import {Component} from "@angular/core";
import { Router, CanActivate} from '@angular/router';
import {LoginService}  from '../service/login.service';
import {User}  from '../model/user';

@Component({
  templateUrl: 'login.component.html',
  providers:[LoginService]
})
export class LoginComponent {

  constructor(private router:Router, private loginService:LoginService) {

    }

    login(event, username, password) {
      alert("dengdengdeng")
        event.preventDefault();
        this.loginService.login(username, password)
            .subscribe(() => {
                this.router.navigate(['']);
            }, this.handleError);
    }

    logout():void {
        localStorage.removeItem('jwt');
    }


    handleError(error) {
        console.log(error.status);
    }

}
